package com.neuedu.oasystem.service.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.neuedu.oasystem.dao.IPrepareMeetingDao;
import com.neuedu.oasystem.dao.impl.PrepareMeetingDaoImpl;
import com.neuedu.oasystem.entity.MeetingPlace;
import com.neuedu.oasystem.entity.PrepareMeeting;
import com.neuedu.oasystem.service.PrepareMeetingService;
import com.neuedu.oasystem.util.DBHelper;
/**
 * PrepareMeeting表实现
 * 	增（增加会议；批量增加会议）
 * 	删（删除会议）
 * 	改（根据会议编号修改其他信息）
 * 	查（查询已有的会议）
 * @author admin
 *
 */
public class PrepareMeetingServiceImpl implements PrepareMeetingService{
	IPrepareMeetingDao prepareMeetingDao;
	public PrepareMeetingServiceImpl() {
		this.prepareMeetingDao = new PrepareMeetingDaoImpl();
	}
	
	/**
	 * 	增加会议
	 */
	@Override
	public boolean add(PrepareMeeting param) {
		Connection connection = DBHelper.openConnection();
		try {
			prepareMeetingDao.setConnection(connection);
			connection.setAutoCommit(false);
			boolean bool = prepareMeetingDao.add(param);
			connection.commit();
			connection.setAutoCommit(false);
			return bool;
		} catch (SQLException e) {
			 //e.printStackTrace();
			if (connection != null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					 //e1.printStackTrace();
				}

			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}
		finally {
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	/**
	 * 	根据会议编号修改其他信息
	 */
	@Override
	public boolean edit(PrepareMeeting param) {
		Connection connection = null;
		connection = DBHelper.openConnection();
		prepareMeetingDao.setConnection(connection);
		try {
			connection.setAutoCommit(false);
			boolean bool = prepareMeetingDao.edit(param);
			connection.commit();
			connection.setAutoCommit(true);
			return bool;
		} catch (SQLException e) {
			// e.printStackTrace();
			if (connection != null) {

				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					//e1.printStackTrace();
				}
			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		} finally {
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	/**
	 * 	删除会议
	 */
	@Override
	public boolean deleteById(int id) {
		Connection connection = null;
		connection = DBHelper.openConnection();
		prepareMeetingDao.setConnection(connection);
		try {
			connection.setAutoCommit(false);
			boolean bool = prepareMeetingDao.deleteById(id);
			connection.commit();
			connection.setAutoCommit(true);
			return bool;
		} catch (SQLException e) {
			//e.printStackTrace();
			if (connection!=null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					//e1.printStackTrace();
				}
			}
		}catch (Exception e) {
			//e.printStackTrace();
		}
		finally {
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	@Override
	public PrepareMeeting findById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 	查询已有的会议
	 */
	@Override
	public List<PrepareMeeting> findAll() {
		Connection connection = null;
		connection = DBHelper.openConnection();
		List<PrepareMeeting> list = new ArrayList<PrepareMeeting>();
		prepareMeetingDao.setConnection(connection);
		try {
		list =prepareMeetingDao.findAll();
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}
		finally {
			DBHelper.closeAll(null, null, connection);
		}
		return list;
	}

	@Override
	public List<PrepareMeeting> findByExample(PrepareMeeting param) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<PrepareMeeting> findByPager(int page, int size) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteByIds(int[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * 	批量增加会议
	 */
	@Override
	public int addAll(List<PrepareMeeting> useparamrs) {
		int result = 0;
		Connection connection  = DBHelper.openConnection();
		prepareMeetingDao.setConnection(connection);
		try {
			connection.setAutoCommit(false);
			result = prepareMeetingDao.addAll(useparamrs);
			connection.commit();
			connection.setAutoCommit(true);
		} catch (SQLException e) {
			//e.printStackTrace();
			if (connection!=null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					//e1.printStackTrace();
				}
			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}
		return result;
	}

	@Override
	public int editAll(List<PrepareMeeting> param) {
		// TODO Auto-generated method stub
		return 0;
	}


}
